#include "GUICfgPhysicalSettingWidget.h"
#include "ui_GUICfgPhysicalSettingWidget.h"

#include "FITK_Interface/FITKInterfaceCustomData/FITKCDInterface.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDCfgPSetPhysical.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDCfgPSetSwitch.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
#include "OperatorsInterface/TreeEventOperator.h"

using namespace GUI;

GUICfgPhysicalSettingWidget::GUICfgPhysicalSettingWidget(EventOper::ParaWidgetInterfaceOperator* oper, QWidget* parent) :
	GUIWidgetBase(parent), _oper(oper)
{
	_ui = new Ui::GUICfgPhysicalSettingWidget();
	_ui->setupUi(this);

	init();
}

GUICfgPhysicalSettingWidget::~GUICfgPhysicalSettingWidget()
{
	if (_ui) {
		delete _ui;
		_ui = nullptr;
	}
}

void GUICfgPhysicalSettingWidget::init()
{
	auto pPhysicalManager = Interface::FITKCDInterface::getInstance()->getCDCfgPhysicalManager();
	_pPhysical = pPhysicalManager->getDataByName("Physical");
	if (_pPhysical == nullptr)
	{
		_pPhysical = new Interface::FITKCDCfgPSetPhysical();
		_pPhysical->setDataObjectName("Physical");

		pPhysicalManager->appendDataObj(_pPhysical);
	}

	auto pSwitchManager = Interface::FITKCDInterface::getInstance()->getCDCfgSwitchManager();
	_pSwitch = pSwitchManager->getDataByName("Switch");
	if (_pSwitch == nullptr)
	{
		_pSwitch = new Interface::FITKCDCfgPSetSwitch();
		_pSwitch->setDataObjectName("Switch");

		pSwitchManager->appendDataObj(_pSwitch);
	}

	setDataToWidget();
}

void GUICfgPhysicalSettingWidget::setDataToWidget()
{
	_ui->doubleSpinBox_Gravity0->setValue(_pPhysical->getGravity()[0]);
	_ui->doubleSpinBox_Gravity1->setValue(_pPhysical->getGravity()[1]);
	_ui->doubleSpinBox_Gravity2->setValue(_pPhysical->getGravity()[2]);
	_ui->doubleSpinBox_SpsSmag->setValue(_pPhysical->getSpsSmag());
	_ui->doubleSpinBox_SpsBlin->setValue(_pPhysical->getSpsBlin());
	_ui->doubleSpinBox_Alpavisc->setValue(_pPhysical->getAlpavisc());
	_ui->checkBox_Realvisc->setChecked(_pPhysical->getRealvisc());

	_ui->checkBox_Pressure_Threshold->setChecked(_pSwitch->getPressure_Threshold());
	_ui->doubleSpinBox_Minimum_Pressure->setValue(_pSwitch->getMinimum_Pressure());
	_ui->checkBox_Density_Reinitial->setChecked(_pSwitch->getDensity_Reinitial());
	_ui->spinBox_Reinitial_Steps->setValue(_pSwitch->getReinitial_Steps());
	_ui->checkBox_Tic->setChecked(_pSwitch->getTic());
	_ui->checkBox_Resort_Fluid->setChecked(_pSwitch->getResort_Fluid());
	_ui->checkBox_Slip->setChecked(_pSwitch->getSlip());
	_ui->checkBox_LJ_Force->setChecked(_pSwitch->getLJ_Force());
	_ui->doubleSpinBox_LJ_Param->setValue(_pSwitch->getLJ_Param());
	_ui->checkBox_PST->setChecked(_pSwitch->getPST());
}




void GUICfgPhysicalSettingWidget::on_doubleSpinBox_Gravity0_valueChanged(double value)
{
	auto d = _pPhysical->getGravity();
	d[0] = value;
	_pPhysical->setGravity(d);
}
void GUICfgPhysicalSettingWidget::on_doubleSpinBox_Gravity1_valueChanged(double value)
{
	auto d = _pPhysical->getGravity();
	d[1] = value;
	_pPhysical->setGravity(d);
}
void GUICfgPhysicalSettingWidget::on_doubleSpinBox_Gravity2_valueChanged(double value)
{
	auto d = _pPhysical->getGravity();
	d[2] = value;
	_pPhysical->setGravity(d);
}
void GUICfgPhysicalSettingWidget::on_doubleSpinBox_SpsSmag_valueChanged(double value)
{
	_pPhysical->setSpsSmag(value);
}
void GUICfgPhysicalSettingWidget::on_doubleSpinBox_SpsBlin_valueChanged(double value)
{
	_pPhysical->setSpsBlin(value);
}
void GUICfgPhysicalSettingWidget::on_doubleSpinBox_Alpavisc_valueChanged(double value)
{
	_pPhysical->setAlpavisc(value);
}
void GUICfgPhysicalSettingWidget::on_checkBox_Realvisc_stateChanged(int state)
{
	_pPhysical->setRealvisc(state);
}


void GUICfgPhysicalSettingWidget::on_checkBox_Pressure_Threshold_stateChanged(int state)
{
	_pSwitch->setPressure_Threshold(state);
}
void GUICfgPhysicalSettingWidget::on_doubleSpinBox_Minimum_Pressure_valueChanged(double value)
{
	_pSwitch->setMinimum_Pressure(value);
}
void GUICfgPhysicalSettingWidget::on_checkBox_Density_Reinitial_stateChanged(int state)
{
	_pSwitch->setDensity_Reinitial(state);
}
void GUICfgPhysicalSettingWidget::on_spinBox_Reinitial_Steps_valueChanged(int value)
{
	_pSwitch->setReinitial_Steps(value);
}
void GUICfgPhysicalSettingWidget::on_checkBox_Tic_stateChanged(int state)
{
	_pSwitch->setTic(state);
}
void GUICfgPhysicalSettingWidget::on_checkBox_Resort_Fluid_stateChanged(int state)
{
	_pSwitch->setResort_Fluid(state);
}
void GUICfgPhysicalSettingWidget::on_checkBox_Slip_stateChanged(int state)
{
	_pSwitch->setSlip(state);
}
void GUICfgPhysicalSettingWidget::on_checkBox_LJ_Force_stateChanged(int state)
{
	_pSwitch->setLJ_Force(state);
}
void GUICfgPhysicalSettingWidget::on_doubleSpinBox_LJ_Param_valueChanged(double value)
{
	_pSwitch->setLJ_Param(value);
}
void GUICfgPhysicalSettingWidget::on_checkBox_PST_stateChanged(int state)
{
	_pSwitch->setPST(state);
}
